//
//  LDY_VoiceTableViewCell.m
//  VoiceProject
//
//  Created by dlios on 15/11/24.
//  Copyright © 2015年 lulu. All rights reserved.
//

#import "LDY_VoiceTableViewCell.h"

#define KWIDTH ([UIScreen mainScreen].bounds.size.width/375)
#define KHEIGHT ([UIScreen mainScreen].bounds.size.height/667)

#define WIDTH self.contentView.frame.size.width
#define HEIGHT self.contentView.frame.size.height

@implementation LDY_VoiceTableViewCell
-(void)dealloc{
    [_picImageView release];
    [_titleNameLabel release];
    [_infoLabel release];
    [_heartImageView release];
    [_likeLabel release];
    [_model release];
    [super dealloc];
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.picImageView = [[UIImageView alloc] init];
        [self.contentView addSubview:self.picImageView];
        [self.picImageView release];
        
        self.titleNameLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.titleNameLabel];
        [self.titleNameLabel release];
        
        self.infoLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.infoLabel];
        [self.infoLabel release];
        
        self.heartImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"likeWhite"]];
        [self.contentView addSubview:self.heartImageView];
        [self.heartImageView release];
        
        self.likeLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.likeLabel];
        [self.likeLabel release];
        
    }
    
    return self;
}


- (void)layoutSubviews
{
    [super layoutSubviews];
    
    self.picImageView.frame = CGRectMake(KWIDTH * 5, KHEIGHT * 10, KWIDTH * 50, KHEIGHT * 50);
    
    self.titleNameLabel.frame = CGRectMake(KWIDTH * 15 + self.picImageView.frame.size.width, 0, KWIDTH * 250, HEIGHT / 2);
    
    self.infoLabel.frame = CGRectMake(KWIDTH * 15 + self.picImageView.frame.size.width, self.titleNameLabel.frame.size.height, KWIDTH * 250, HEIGHT / 4);
    
    self.heartImageView.frame = CGRectMake(KWIDTH * 375 - KWIDTH * 30, KHEIGHT * 10, KWIDTH * 25, KHEIGHT * 25);
    
    self.heartImageView.frame = CGRectMake(KWIDTH * 375 - KWIDTH * 30, KHEIGHT * 10 + self.heartImageView.frame.size.height, KWIDTH * 50, KHEIGHT * 25);
}


- (void)setModel:(LDY_VoiceModel *)model
{
    if (_model != model) {
        [_model release];
        _model = [model retain];
    }
    
    [self.picImageView sd_setImageWithURL:[NSURL URLWithString:model.pic] placeholderImage:[UIImage imageNamed:@"wait"]];
    
    self.titleNameLabel.text = model.name;
    self.titleNameLabel.font = [UIFont systemFontOfSize:15];
    
    self.infoLabel.text = model.info;
    self.infoLabel.font = [UIFont systemFontOfSize:14];
    self.infoLabel.textColor = [UIColor grayColor];
    
    self.likeLabel.text = [NSString stringWithFormat:@"%@", model.like_count];
}


- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
